package cn.newtest.bi.collection.model;

import java.io.Serializable;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.hibernate.annotations.GenericGenerator;

/**
 * 
 * 
 * @author <a href="mailto: baiyibing@gmail.com">王锤</a>
 * @version $Revision$
 * 
 */
@Entity
@org.hibernate.annotations.Entity(dynamicInsert=true,dynamicUpdate=true)
@Table(name="rpt_all_soinstance")
public class SoInstance implements Comparable<Object>, Serializable {

	private static final long serialVersionUID = 2817921981220502762L;

	@Id
	@Column(name="item_guid",length=38)
	@GenericGenerator(name="SoInstance-assigned",strategy="assigned")
	private String guid;

	@Column(name="item_code",length=45)
	private String code;

	@Column(name="item_name",length=45)
	private String name;

	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="catalog_guid")
	private Catalog catalog;

	@Basic
	private Integer status;

	@Column(length=100)
	private String flag;

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public String getFlag() {
		return flag;
	}

	public void setFlag(String flag) {
		this.flag = flag;
	}

	public Catalog getCatalog() {
		return catalog;
	}

	public void setCatalog(Catalog catalog) {
		this.catalog = catalog;
	}

	public String getGuid() {
		return guid;
	}

	public void setGuid(String guid) {
		this.guid = guid;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Transient
	public String getCatalogGuid() {
		return getCatalog().getGuid();
	}

	/**
	 * @see java.lang.Comparable#compareTo(Object)
	 */
	public int compareTo(Object object) {
		SoInstance myClass = (SoInstance) object;
		return new CompareToBuilder().append(this.guid, myClass.guid).append(
				this.catalog, myClass.catalog).append(this.name, myClass.name)
				.append(this.code, myClass.code).toComparison();
	}

	/**
	 * @see java.lang.Object#equals(Object)
	 */
	public boolean equals(Object object) {
		if (!(object instanceof SoInstance)) {
			return false;
		}
		SoInstance rhs = (SoInstance) object;
		return new EqualsBuilder().appendSuper(super.equals(object)).append(
				this.guid, rhs.guid).append(this.catalog, rhs.catalog).append(
				this.name, rhs.name).append(this.code, rhs.code).isEquals();
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		return new HashCodeBuilder(402932085, -1832537933).appendSuper(
				super.hashCode()).append(this.guid).append(this.catalog)
				.append(this.name).append(this.code).toHashCode();
	}

	/**
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return new ToStringBuilder(this).append("guid", this.guid).append(
				"catalogGuid", this.getCatalogGuid()).append("name", this.name)
				.append("catalog", this.catalog).append("code", this.code)
				.toString();
	}

}
